import java.util.Arrays;

public class Main {
    public static void main(String[] args) {

        Main main = new Main();
        int[] nums={2,2,2,3};
        System.out.println(main.findNumberOfLIS(nums));
    }

    //最长递增子序列的个数
    public int findNumberOfLIS(int[] nums) {
        int n = nums.length;
        int[] len = new int[n];
        int[] count = new int[n];
        for (int i = 0; i < n; i++) {
            len[i] = 1;
            count[i] = 1;
        }
        int retlen = 1;
        int retcount = 1;
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                if (nums[i] > nums[j]) {
                    if (len[i] == len[j] + 1) {
                        count[i] += count[j];
                    } else if (len[i] < len[j] + 1) {
                        len[i] = len[j] + 1;
                        count[i] = count[j];
                    }
                }
            }
            if (retlen == len[i]) {
                retcount += count[i];
            } else if (retlen < len[i]) {
                retlen = len[i];
                retcount = count[i];
            }
        }
        return retcount;
    }


    //最长数对链
    public int findLongestChain(int[][] pairs) {
        //预处理
        Arrays.sort(pairs, (a,b)->a[0]-b[0]);
        int n = pairs.length;
        int[] dp=new int[n];
        for (int i=0;i<n;i++){
            dp[i]=1;
        }
        int ret=1;
        for(int i=1;i<n;i++){
            for(int j=0;j<i;j++){
                if(pairs[i][0]>pairs[j][1]){
                    dp[i]=Math.max(dp[i],dp[j]+1);
                    ret=Math.max(ret,dp[i]);
                }
            }
        }
        return ret;
    }

    public int findLongestChain2(int[][] pairs) {
        Arrays.sort(pairs, (a, b) -> a[1] - b[1]);
        int curr = Integer.MIN_VALUE;
        int ans = 0;

        for (int[] pair : pairs) {
            if (pair[0] > curr) {
                ans++;
                curr = pair[1];
            }
        }
        return ans;
    }
}